<?php
// ------------------------------------------------------------------
// NEEDED STUBS FOR THIS EXAMPLE
// ------------------------------------------------------------------


// this will include all needed files to be able to build a Request
include_once($CONF["STUBS_FOLDER"]."Map24Geocoder/Map24Geocoder.php5");


// ------------------------------------------------------------------
// NEEDED PARAMETERS FOR THIS REQUEST
// ------------------------------------------------------------------


// Set $SynchronizeClient to TRUE, to see found objects on the map
$SynchronizeClient = TRUE;

// definition of the adresses to geocode

// the 1st address
$addrIdx=0;
$addr[$addrIdx]['Street']    = 'Eckenheimer Landstr.';
$addr[$addrIdx]['Zip']       = '60435';
$addr[$addrIdx]['City']      = 'Frankfurt';
$addr[$addrIdx]['Country']   = 'DE';

// the 2nd address
$addrIdx++;
$addr[$addrIdx]['Street']    = 'Duesseldorfer Str.';
$addr[$addrIdx]['Zip']       = '65760';
$addr[$addrIdx]['City']      = 'Eschborn';
$addr[$addrIdx]['Country']   = 'DE';

// 3rd address
$addrIdx++;
$addr[$addrIdx]['Street']    = 'Goethestr.';
$addr[$addrIdx]['Zip']        = '60311';
$addr[$addrIdx]['City']      = 'Frankfurt';
$addr[$addrIdx]['Country']   = 'DE';

//4th address
$addrIdx++;
$addr[$addrIdx]['Street']    = 'Kurfuerstendamm';
$addr[$addrIdx]['Zip']        = '10629';
$addr[$addrIdx]['City']      = 'Berlin';
$addr[$addrIdx]['Country']   = 'DE';

//5th address
$addrIdx++;
$addr[$addrIdx]['Street']    = 'Millerntordamm';
$addr[$addrIdx]['Zip']        = '20359';
$addr[$addrIdx]['City']      = 'Hamburg';
$addr[$addrIdx]['Country']   = 'DE';



// ------------------------------------------------------------------
// BUILDING THE REQUEST
// ------------------------------------------------------------------


// definition of the request header with Map24ID and SessionID
$header = new RequestHeader();
$header->Map24ID  = $CONF['MAP24_ID'];
$header->ClientID = $CONF['SESSION_ID'];

// definition of the request body
$request = new GeocodeAddressesRequest();
$request->Addresses = array();

// add the Array of Address Objects
for($objIdx=0;$objIdx<count($addr);$objIdx++)
{
	$request->Addresses[$objIdx]= new Address();
	$request->Addresses[$objIdx]->Street=$addr[$objIdx]['Street'];
	$request->Addresses[$objIdx]->ZIP=$addr[$objIdx]['Zip'];
	$request->Addresses[$objIdx]->City=$addr[$objIdx]['City'];
	$request->Addresses[$objIdx]->Country=$addr[$objIdx]['Country'];
}
	$request->MaxNoOfAlternatives = 1;
	$request->SynchronizeClient = $SynchronizeClient;


// ------------------------------------------------------------------
// EXECUTE THE REQUEST
// ------------------------------------------------------------------


// in this object the SoapClient will be initiated and executed
$geocoder = new Map24Geocoder($CONF['MAPTP_SYSTEM'],$CONF['MAP24_ID'],$CONF['SESSION_ID']);

$response = $geocoder->GeocodeAddresses($header,$request);


// ------------------------------------------------------------------
// OUTPUT THE RESULT
// ------------------------------------------------------------------


if(isset($response->GeocodedAddresses) && count($response->GeocodedAddresses) > 0)
{
	for($objIdx=0;$objIdx<count($response->GeocodedAddresses);$objIdx++)
	{
		$counter++;
		$resultString .= "<div><b>".$counter.".</b><br/>";
		$resultString.= "Street: ".$response->GeocodedAddresses[$objIdx]->Alternatives[0]->Street."<br/>";
		$resultString.= "HouseNo: ".$response->GeocodedAddresses[$objIdx]->Alternatives[0]->HouseNo."<br/>";
		$resultString.= "ZIP, City: ".$response->GeocodedAddresses[$objIdx]->Alternatives[0]->ZIP." ".$response->GeocodedAddresses[$objIdx]->Alternatives[0]->City."<br/>";
		$resultString.= "Country: ".$response->GeocodedAddresses[$objIdx]->Alternatives[0]->Country."<br/>";
		$resultString.= "<b>Longitude: ".$response->GeocodedAddresses[$objIdx]->Alternatives[0]->Coordinate->Longitude."<br/>";
		$resultString.= "Latitude: ".$response->GeocodedAddresses[$objIdx]->Alternatives[0]->Coordinate->Latitude."</b><br/><br/>";
		$resultString .= "</div>";
	}
}
else
{
	$resultString = "Sorry, no answer from the webservices";
}

?>